<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Author: Duy Hoan
 * Description: Home model class
 */
class Login_model extends CI_Model{
    
    function __construct(){
        parent::__construct();
        $this->load->database();
    }
    
	public function validate($user,$pass){
        // grab user input
        $username = $this->security->xss_clean($user);
        $password = $this->security->xss_clean($pass);
		$password = md5($pass);
        // Prep the query
        $this->db->where('ten_nguoidung', $username);
        $this->db->where('matkhau_nguoidung', $password);
        $query = $this->db->get('vtv4_nguoidung');
        // Let's check if there are any results
        if($query->num_rows == 1)
        {
            // If there is a user, then create session data
            $row = $query->row();
            $data = array(
                    'user_id' => $row->id_nguoidung,
                    'user_name' => $row->ten_nguoidung,
            );
            
            $login = $this->log_model->saveLog(3,null,null,"");
            if($login){
            	$this->session->set_userdata($data);            
            	return true;
            }
            else return false;
        }
        return false;
    }
    /*
 	function saveLog($id_user){				
    	date_default_timezone_set('UTC');
    	$create_date = date("Y-m-d H:i:s");
    	$data = array(
    		'LOGIN_LAST' => $create_date
    	);
    	$this->db->where('ID', $id_user);
    	$result = $this->db->update('users', $data);
    	return $result;
    }
    
	function selectUser($userid){
		$this->db->where('ID',$userid);
        $query = $this->db->get('users');
        return $query->row();     	
    }   
    */
}